﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PJAA_Inventory_and_AR___Prototype
{
    public partial class Replenish_Inventory : Form
    {
        SQLMaster master;
        
       

        public Replenish_Inventory()
        {
            //added this block to make the form transparent
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.BackColor = Color.Transparent;

            InitializeComponent();
            master = new SQLMaster();
            
            loadinventory();
        }



        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 3)
            {
                if (RepInv_DGV.SelectedCells[0].Value == null)
                { MessageBox.Show("Please select a customer first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
                else
                {
                    AddInvQty addinvqty = new AddInvQty(RepInv_DGV.SelectedCells[0].Value.ToString(), Convert.ToUInt16(RepInv_DGV.SelectedCells[2].Value.ToString()), (RepInv_DGV.SelectedCells[1].Value.ToString()));
                    addinvqty.ShowDialog();
                }

            }
        }


        public void loadinventory()
        {
            List<object[]> dataCompare = new List<object[]>();
            dataCompare = master.loadPJAAInventory();
            RepInv_DGV.Rows.Clear();

            foreach (object[] strArray in dataCompare)
            {
                if (RepInv_ItemName_TxtBox.Text != string.Empty)
                {
                    if ((strArray[1]).ToString().ToLower().Contains(RepInv_ItemName_TxtBox.Text.ToLower()))
                    {
                        RepInv_DGV.Rows.Add(strArray);
                    }
                }
                else
                    RepInv_DGV.Rows.Add(strArray);
            }
        }

        private void RepInv_ItemName_TxtBox_TextChanged(object sender, EventArgs e)
        {
            loadinventory();
        }


        private void RepInv_Cancel_Btn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button_Refresh_Click(object sender, EventArgs e)
        {
            loadinventory();
        }

    }
}
